<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <button @click="isShow=!isShow">{{isShow?'显示':'隐藏'}}</button>
    <keep-alive>
      <home-page v-if="isShow"></home-page>
    </keep-alive>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp, h } = Vue;
    const app = createApp({
      data() {
        return {
          isShow: true
        }
      },
    });
    const HomePage = {
      template: `
        <div>
          <h2>这是首页</h2>  
          <input type="text" v-model="msg"/>
          {{ msg }}
        </div>
      `,
      data() {
        return {
          msg: ''
        }
      },
      mounted (){
        console.log('组件渲染完成');
      },
      beforeUnmount(){
        console.log('组件即将卸载');
      },
      activated () {
        console.log('组件使用了-activated');
      },
      deactivated () {
        console.log('组件停用了-deactivated');
      }
    }
    app.component('HomePage', HomePage);
    app.mount('#app')
  </script>
</body>
</html>